 
  

 






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=230 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:10 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
<head>
 <title>
  Java Practices -> Don't bury dialogs
 </title>
 <link rel="stylesheet" type="text/css" href="../stylesheet8.css" media="all">
 
 <link rel="shortcut icon" href='../images/favicon.ico' type="image/vnd.microsoft.icon">
 <meta name="description" content="Concise presentations of java programming practices, tasks, and conventions, amply illustrated with syntax highlighted code examples.">
 
 <meta name='keywords' content='java,java programming,java practices,java idiom,java style,java design patterns,java coding conventions,'>
 
 
</head>
 
<body>


<div class='menu-bar'>
 
  <a href='../home/HomeAction.html' title='Table of Contents'>Home</a> |
  <a href='../vote/VoteSummaryAction-2.html' title='View Poll Results'>Poll</a> |
   
  <A href='../feedback/FeedbackAction451f-2.html?Operation=Show' title='Send Your Feedback'>Wiki</a> |
  <b><a href='../source/SourceAction-2.html' title='Grab Source Code'>Source Code</a></b><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |

  <a href='http://www.web4j.com/Java_Web_Application_Framework_Overview.jsp?From=1' title='Free Download - Java Web Application Framework'><b>WEB4J</b></a> |
  
  <a href='http://www.date4j.net/' title='Replacement for java.util.Date'><b>DATE4J</b></a> |

   <a href='../references/ReferencesAction-2.html' title='References'>Links</a>
   
  <form action='http://www.javapractices.com/search/SearchAction.do' method='get' class='search-form'>
   <input type='text' name='SearchTerms' value="" size=12 maxlength=50 class='search'>
   <input type='submit' value="Search">
  </form>
 
</div>

<P>



  

 






<p class="display-messages">

 

 

</p>


<div class="main-layout">
 
   

 




<div class='page-title'>Don't bury dialogs</div>

<div class='main-body'>
 
<br>
The <a href='http://java.sun.com/javase/6/docs/api/javax/swing/JDialog.html'>JDialog</a> 
class uses the idea of an <em>owner object</em>. 
The owner is the class which is using the JDialog, either a Frame or another Dialog.
It's possible to pass null as the owner, but it's a very bad habit. 
If no owner is defined, then various highly desirable behaviors are lost:
<ul>
 <li>inheriting position from the owner
 <li>inheriting application icon from the owner
 <li>correct ALT+TAB behavior when switching between applications
</ul>

<P>The last point may seem minor at first glance, but it's actually a major problem. 
When proper ALT+TAB behavior is absent, the dialog can easily get 'lost' behind your application.
Many end users have no idea how to recover access to such lost dialogs. 
This becomes especially serious when the dialog is <em>modal</em> (which they usually are) since, not only can the user not find the dialog, but they are <em>unable to interact with any other screens in the application</em>.
In this situation, many end users will naturally conclude that the application is hung, and they will do what they always do when an application is hung - <span class='highlight'>they will reboot the machine</span>.

<P>This issue can be addressed in your <a href='TopicAction7910-2.html?Id=150'>Standard Dialog</a> class, which may enforce the rule that an owner be specified. 

<P>As a backup style, your Standard Dialog might use the <em>active frame</em> as its owner, if none is explicitly passed by the caller.
Here is a code snippet showing how to get the active frame.
<br>
<PRE>

<span class='keyword'>import</span> java.awt.Frame;

<span class='keyword'>public</span> <span class='keyword'>final</span> <span class='keyword'>class</span> ActiveFrame {

  <span class='comment'>/** Return the currently active frame. */</span>
  <span class='keyword'>public</span> <span class='keyword'>static</span> Frame getActiveFrame() {
    Frame result = <span class='keyword'>null</span>;
    Frame[] frames = Frame.getFrames();
    <span class='keyword'>for</span> (<span class='keyword'>int</span> i = <span class='literal'>0</span>; i &lt; frames.length; i++) {
      Frame frame = frames[i];
      <span class='keyword'>if</span> (frame.isVisible()) { 
        result = frame;
        <span class='keyword'>break</span>;
      }
    }
    <span class='keyword'>return</span> result;
  }
} 
</PRE>
<br>
<br>
<br>

</div>




<div class='topic-section'>See Also :</div>
<div class='main-body'>
 
  
  <a href='TopicAction7910-2.html?Id=150'>Standardized dialogs</a> <br>
 
</div>


<div class='topic-section'>Would you use this technique?</div>
<div class='main-body'>
  
  <form action="http://www.javapractices.com/vote/AddVoteAction.do" method='post'>
    Yes<input type='radio' name='Choice' value='Y' >
    &nbsp;&nbsp;No<input type='radio' name='Choice' value='N'>
    &nbsp;&nbsp;Undecided<input type='radio' name='Choice' value="?" >
    &nbsp;&nbsp;<input type=submit value="Vote" >
    <input type='hidden' name='Operation' value='Apply'>
    <input type='hidden' name='TopicId' value='230'>
  </form>
</div>

<div style='height:10.0em;'></div>

 
 
</div>

  

 





<div align='center' class='legalese'>  
&copy; 2011 Hirondelle Systems |
<a href='../source/SourceAction-2.html'><b>Source Code</b></a><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |
<a href="mailto:webmaster@javapractices.com">Contact</a> |
<a href="http://creativecommons.org/licenses/by-nc-sa/1.0/">License</a> |
<a href='../apps/cjp.rss'>RSS</a>
<!-- ukey="2AC36CD2" -->
<!-- ckey="16DF3D87" -->
<br>

 Individual code snippets can be used under this <a href='../LICENSE.txt'>BSD license</a> - Last updated on June 6, 2010.<br>
 Over 150,000 unique IPs last month - <span title='Java Practices 2.6.5, Mon May 16 00:00:00 EDT 2011'>Built with</span> <a href='http://www.web4j.com/'>WEB4J</a>.<br>
 - In Memoriam : Bill Dirani -
</div>

<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2633428-1";
urchinTracker();
</script>



</body>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=230 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:10 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
</html>
